<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title></title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

        </head>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            bindgrid();
                            $("#uploadbtn").bind("click", function (e) {
                                $("#uploadpicker").click();
                            });
                        });
                    </script>
                    <script>
                        function del(node) {
                            $.ajax({
                                type: "delete",
                                url: 'qm/oos/data/delete?' + 'osId=' + node.osId,
                                //                dataType: "xml",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#add').window('close');
                                    bindgrid();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }


                        function editrow() {
                            //编辑用户
                            var row = $('#dg').datagrid('getSelected');
                            if (row) {
                                $('#add').window('open');
                                $('#fm').form('load', row);

                            } else {
                                $.messager.alert('消息', '请选中一条数据');
                            }
                        }
                    </script>
                    <script>
                        var selectedTaskFileList = [];//行动项文件列表
                        var selectedImproveFileList = [];//措施文件列表
                        var selectedFileList = [];//已选文件列表
                        var succsessCount = 0;//上传成功文件个数
                        var errorCount = 0;//上传失败文件个数
                        var editIndex = undefined;

                        // 行编辑结束
                        function endEditing() {

                            if (editIndex == undefined) {
                                return true
                            }
                            if ($('#improes').datagrid('validateRow', editIndex)) {
                                $('#improes').datagrid('endEdit', editIndex);
                                editIndex = undefined;
                                return true;
                            } else {
                                $.messager.alert('提示', '有未填写数据!')
                                return false;
                            }
                        }

                        function save(action) {
                            if (!endEditing()) {
                                return;
                            }
                            if (!$('#fm').form('validate')) {
                                $.messager.show({
                                    title: '提示',
                                    msg: '有未填写数据！',
                                    timeout: 3000,
                                    showType: 'slide'
                                });
                                return;
                            }
                            $('#improes').datagrid('acceptChanges');

                            const improvels = $('#improes').datagrid('getRows')
                            let model = {
                                osId: $('#osId').val(),
                                status: '0',
                                oosType: $('#oosType').combobox('getValue'),
                                oosTypeDecide: $('#oosTypeDecide').textbox('getValue'),
                                oosImprovesModels: improvels
                            }
                            saveAjax(model, action)
                        }

                        function saveAjax(model, action) {
                            let osId = model.osId
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'qm/oos/data/update',
                                data: JSON.stringify(model),
                                contentType: "application/json",
                                success: function (data) {
                                },
                                complete: function (XMLHttpRequest) {
                                    if (XMLHttpRequest.responseJSON.code != 60200) {
                                        $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                                    } else {
                                        // saveAttch(osId, osId, action)
                                        if ('save' == action) {
                                            $.messager.show({
                                                title: '提示',
                                                msg: XMLHttpRequest.responseJSON.msg,
                                                timeout: 3000,
                                                showType: 'slide'
                                            });
                                            let dg = $('#dg');
                                            dg.datagrid('enableFilter');
                                            dg.datagrid('load');
                                            $('#detaillWindow').window('close');
                                            oosDataDetailAjax(osId)
                                        } else {
                                            commit(XMLHttpRequest.responseJSON.data)
                                        }
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })

                        }

                        /**
                         * 完成
                         */
                        function commit(obj) {
                            obj.status = '1'
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'qm/oos/data/update',
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                    } else {
                                        $.messager.alert('消息', data.msg);
                                        let dg = $('#dg');
                                        dg.datagrid('enableFilter');
                                        dg.datagrid('load');
                                        $('#detaillWindow').window('close');
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        /**
                         *  按条件查询报价列表
                         */
                        function selectList() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            var status = $('#select-status').combobox('getValue');
                            var dg = $('#dg');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load', {
                                startTime: startTime ? startTime : '',
                                endTime: endTime ? endTime : '',
                                status: status ? status : ''
                            });
                        }

                        function exportList() {
                            let startTime = $('#startTime').datebox('getValue')
                            let endTime = $('#endTime').datebox('getValue')
                            let status = $('#select-status').combobox('getValue')
                            var form = [];
                            form.push('startTime=' + (startTime ? startTime : ''));
                            form.push('endTime=' + (endTime ? endTime : ''));
                            form.push('status=' + (status ? status : ''));
                            let url = 'api/qm/oos/data/export'
                            let xhr = new XMLHttpRequest()
                            xhr.open('POST', url, true)
                            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
                            xhr.setRequestHeader('token', localStorage.getItem('token'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function () {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = 'OOS数据' + new Date().toLocaleDateString() + '-' + new Date().toLocaleTimeString() + '.xlsx'
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                }
                            }
                            xhr.send(form.join('&'))
                        }
                    </script>
                    <style scoped="scoped">
                        .textbox {
                            height: 20px;
                            margin: 0;
                            padding: 0 2px;
                            box-sizing: content-box;
                        }

                        /*.table tr {
height: 15px;
}*/
                    </style>
                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" /> <label
                                    style="margin-left: 20px; font-size: 12px;">状态：</label>
                                <input class="easyui-combobox" id="select-status" name="status" style="width: 80px;"
                                    data-options="valueField: 'value',editable:false,
						textField: 'label',panelHeight:'auto',data: [{
							label: '全部',
							value: ''
						},{
							label: '待完成',
							value: '0',
							selected:true
						},{
							label: '已完成',
							value: '1'
						}]">
                                </select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
                                    class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                    onclick="selectList()">查询</a>
                                <a id="export" href="javascript:void(0)" class="easyui-linkbutton"
                                    data-options="iconCls:'icon-export'" onclick="exportList()">导出</a>
                        </div>
                        <%--oos列表 --%>
                            <table id="dg"></table>
                            <%-- oos详情/编辑 --%>
                                <div id="detaillWindow" class="easyui-window" closed="true" modal="true" title="OOS详情"
                                    style="width: 930px; height: 400px; padding: 5px 5px; top: 50px;">
                                    <div id="tabs" class="easyui-tabs" data-options="selected:0"
                                        style="width: 885px; height: 350px">
                                        <div title="基本信息" style="padding: 5px;">
                                            <form id="oosForm">
                                                <table>
                                                    <tr>
                                                        <input id="osId" name="osId" type="hidden" />
                                                        <td>
                                                            <div class="ssec-label">OOS编码：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osCode" name="osCode" class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">采样时间：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osSamplingTime" name="osSamplingTime"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">产品名称：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osSampleName" name="osSampleName"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">样品编码：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osSampleCode" name="osSampleCode"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">通知单类型：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osNoticeType" name="osNoticeType"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">级别：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osOsLevel" name="osOsLevel"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">客商名称：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osMerchantName" name="osMerchantName"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">产品批号：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osBatchCode" name="osBatchCode"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">包装规格：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osPackageDescr" name="osPackageDescr"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">车牌号：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osCarNo" name="osCarNo"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">包装数量：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="osPackageQuantity" name="osPackageQuantity"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">创建时间：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="createTime" name="createTime"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">是否有效：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input class="easyui-combobox" id="oosType"
                                                                    name="oosType" style="width: 80px;" data-options="required:false,valueField: 'value',editable:false,
						textField: 'label',panelHeight:'auto',data: [{
							label: '无效',
							value: '0',
							selected:true
						},{
							label: '有效',
							value: '1'
						}]">
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">判定说明：</div>
                                                        </td>
                                                        <td>
                                                            <input class="easyui-textbox"
                                                                data-options="required:false,multiline:true"
                                                                id="oosTypeDecide" value=""
                                                                style="width:200px;height:100px">
                                                        </td>
                                                    </tr>
                                                </table>
                                            </form>
                                            </form>
                                        </div>
                                        <div title="异常项明细" style="padding: 5px;">
                                            <table id="oosItems"></table>
                                        </div>
                                        <%-- 将”行动项明细” 改为“各部门自查” --%>
                                            <div title="各部门自查" style="padding: 5px;">
                                                <table id="tasks"></table>
                                            </div>
                                            <%-- 将”整改措施” 改为“行动项明细” --%>
                                                <div title="行动项明细" style="padding: 5px;">
                                                    <table id="improes"></table>
                                                </div>

                                    </div>
                                </div>
                                <%-- 各部门自查详情 --%>
                                    <div id="taskDetaillWindow" class="easyui-window" closed="true" modal="true"
                                        title="部门自查详情"
                                        style="width: 930px; height: 400px; padding: 5px 5px; top: 50px;">
                                        <div id="taskTabs" class="easyui-tabs" data-options="selected:0"
                                            style="width: 885px; height: 350px">
                                            <div title="部门自查详情" style="padding: 5px;">
                                                <table>
                                                    <tr>
                                                        <input id="taskId" name="taskId" type="hidden" />
                                                        <td>
                                                            <div class="ssec-label">执行部门：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="executDeptName" name="executDeptName"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">执行人：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="executName" name="executName"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">计划完成时间：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="planCompleteTime" name="planCompleteTime"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">提交时间：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="commitTime" name="commitTime"
                                                                    class="easyui-textbox"
                                                                    data-options="readonly:true" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">情况说明：</div>
                                                        </td>
                                                        <td colspan="5">
                                                            <div class="ssec-text normal">
                                                                <input id="taskContent" name="taskContent"
                                                                    class="easyui-textbox"
                                                                    style="width:350px;height:60px"
                                                                    data-options="readonly:true,multiline:true" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                            <div title="附件" style="padding: 5px;">
                                                <table>
                                                    <tr>
                                                        <td><label style="width: 40%; text-align: right;">附件：</label>
                                                            <ul id="taskFileList"></ul>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    <%-- 行动项详情 --%>
                                        <div id="improvelDetaillWindow" class="easyui-window" closed="true" modal="true"
                                            title="行动项详情"
                                            style="width: 930px; height: 400px; padding: 5px 5px; top: 50px;">
                                            <div id="impTabs" class="easyui-tabs" data-options="selected:0"
                                                style="width: 885px; height: 350px">
                                                <div title="行动项详情" style="padding: 5px;">
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <div class="ssec-label">计划完成时间：</div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-text normal">
                                                                    <input id="impPlanTime" name="impPlanTime"
                                                                        class="easyui-textbox"
                                                                        data-options="readonly:true" />
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-label">实际完成时间：</div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-text normal">
                                                                    <input id="impRealTime" name="impRealTime"
                                                                        class="easyui-textbox"
                                                                        data-options="readonly:true" />
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-label">责任部门名称：</div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-text normal">
                                                                    <input id="impDutyDeptName" name="impDutyDeptName"
                                                                        class="easyui-textbox"
                                                                        data-options="readonly:true" />
                                                                </div>
                                                            </td>
                                                        </tr>
                                                        <tr>

                                                            <td>
                                                                <div class="ssec-label">责任人：</div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-text normal">
                                                                    <input id="impDutyPersonName"
                                                                        name="impDutyPersonName" class="easyui-textbox"
                                                                        data-options="readonly:true" />
                                                                </div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-label">复核人：</div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-text normal">
                                                                    <input id="impApprovelName" name="impApprovelName"
                                                                        class="easyui-textbox"
                                                                        data-options="readonly:true" />
                                                                </div>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <div class="ssec-label">问题点：</div>
                                                            </td>
                                                            <td colspan="5">
                                                                <div class="ssec-text normal">
                                                                    <input id="impExplain" name="impExplain"
                                                                        class="easyui-textbox"
                                                                        style="width:350px;height:60px"
                                                                        data-options="readonly:true,multiline:true" />
                                                                </div>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <input id="impId" name="impId" type="hidden" />
                                                            <td>
                                                                <div class="ssec-label">纠正预防措施：</div>
                                                            </td>
                                                            <td colspan="5">
                                                                <div class="ssec-text normal">
                                                                    <input id="improveContent" name="improveContent"
                                                                        class="easyui-textbox"
                                                                        style="width:350px;height:60px"
                                                                        data-options="readonly:true,multiline:true" />
                                                                </div>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <div class="ssec-label">整改描述：</div>
                                                            </td>
                                                            <td colspan="5">
                                                                <div class="ssec-text normal">
                                                                    <input id="impCompleteDescr" name="impCompleteDescr"
                                                                        class="easyui-textbox"
                                                                        style="width:350px;height:60px"
                                                                        data-options="readonly:true,multiline:true" />
                                                                </div>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </div>
                                                <div title="附件" style="padding: 5px;">
                                                    <table>
                                                        <tr>
                                                            <td><label
                                                                    style="width: 40%; text-align: right;">附件：</label>
                                                                <ul id="impFileList"></ul>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                    </div>
        </body>
        <script>
            function detail(index) {
                const rows = $('#dg').datagrid('getRows')
                let row = rows[index]
                if (!row) {
                    $.messager.error('错误', '请至少选择一行数据')
                    return
                }
                oosDataDetailAjax(row.osId)
            }

            function oosDataDetailAjax(osId) {
                $.ajax({
                    type: 'get',
                    url: 'qm/oos/data/selectInfor?osId=' + osId,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 60200) {
                            let oosModel = data.data
                            getFileList(oosModel.osId)
                            setOosDetail(oosModel)
                            setTabToolBar(oosModel)
                        } else {
                            $.messager.alert('消息', data.msg);
                        }
                    }
                })
                $('#detaillWindow').window('open')
                $('#tabs').tabs('select', 0)
            }

            function setOosDetail(oosModel) {
                if (!oosModel) {
                    return
                }
                $('#osId').val(oosModel.osId)
                $('#osCode').textbox('setValue', oosModel.osCode)
                $('#osSamplingTime').textbox('setValue', oosModel.osSamplingTime)
                $('#osSampleName').textbox('setValue', oosModel.osSampleName)
                $('#osSampleCode').textbox('setValue', oosModel.osSampleCode)
                $('#osNoticeType').textbox('setValue', oosModel.osNoticeType)
                $('#osOsLevel').textbox('setValue', oosModel.osOsLevel)
                $('#osMerchantName').textbox('setValue', oosModel.osMerchantName)
                $('#osBatchCode').textbox('setValue', oosModel.osBatchCode)
                $('#osPackageDescr').textbox('setValue', oosModel.osPackageDescr)
                $('#osCarNo').textbox('setValue', oosModel.osCarNo)
                $('#osPackageQuantity').textbox('setValue', oosModel.osPackageQuantity)
                $('#createTime').textbox('setValue', oosModel.createTime)
                $('#oosType').combobox('setValue', oosModel.oosType)
                $('#oosTypeDecide').textbox('setValue', oosModel.oosTypeDecide)
                const oosItemsArr = oosModel.itemModelList
                setOosItemDataGrid(oosItemsArr)
                const tasksArr = oosModel.taskModelList
                setOosTaskDataGrid(tasksArr)
                const improvels = oosModel.oosImprovesModels
                setOosImprovelsDataGrid(improvels)
            }

            function setOosImprovelsDataGrid(data) {
                $('#improes').datagrid({
                    data, data,
                    iconCls: 'icon-application',
                    clientPaging: true,
                    remoteFilter: false,
                    filterDelay: 0,
                    width: 850,
                    height: 300,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pagination: false,
                    toolbar: [
                        {
                            text: '新增',
                            iconCls: 'icon-add',
                            handler: function () {
                                $('#improes').datagrid('appendRow', {});
                            }
                        }, '-',
                        {
                            text: '移除',
                            iconCls: 'icon-remove',
                            handler: function () {
                                let row = $('#improes').datagrid('getSelected');
                                if (row) {
                                    $.messager.confirm('提示', '本条数据已输入的整改描述及附件会被删除，确定要删除吗?',
                                        function (r) {
                                            if (r) {
                                                // 获取索引
                                                let index = $('#improes').datagrid('getRowIndex', row)
                                                // 删除前结束编辑
                                                $('#improes').datagrid('endEdit', editIndex);
                                                editIndex = undefined;
                                                // 删除行
                                                $('#improes').datagrid('deleteRow', index)
                                                // 删除数据库的该数据
                                                $.ajax({
                                                    type: "delete",
                                                    dataType: "json",
                                                    url: 'qm/oos/improves/delete?impId=' + row.impId,
                                                    success: function (data) {
                                                        //   $.messager.alert('消息', data.msg);
                                                    },
                                                    error: function (XMLHttpRequest, textStatus,
                                                        errorThrown) {
                                                        //  $.messager.alert('消息', errorThrown);
                                                    }
                                                })

                                            }
                                        });
                                } else {
                                    $.messager.alert('消息', '请选中一条要删除的数据');
                                }
                            }
                        }],
                    columns: [
                        [
                            {
                                field: 'impId',
                                title: '措施id',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'osId',
                                title: 'oosID',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impExplain',
                                title: '问题点',
                                editor: {
                                    type: 'textbox',
                                    options: {
                                        required: true,
                                        width: 100
                                    }
                                },
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'improveContent',
                                title: '纠正预防措施',
                                editor: {
                                    type: 'textbox',
                                    options: {
                                        required: true,
                                        width: 100
                                    }
                                },
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impPlanTime',
                                title: '计划完成时间',
                                editor: {
                                    type: 'datebox', editable: false
                                },
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impDutyDeptCode',
                                title: '责任部门',
                                width: 200,
                                editor: {
                                    type: 'combotree',
                                    options: {
                                        editable: false,
                                        required: true,
                                        url: 'DeptManage/DeptListJson_combobox?deptid=982ce640-1567-4b68-a324-4aa5bd1f1804'
                                    }
                                },
                                formatter: function (val, rec) {
                                    return val ? unescape(rec.impDutyDeptName) : ''
                                }
                            },
                            {
                                field: 'impDutyDeptName',
                                title: '责任部门',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impRealTime',
                                title: '实际完成时间',
                                /* editor: {
                                     type: 'datebox', editable: false
                                 },*/
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impCompleteDescr',
                                title: '完成描述',
                                /*editor: {
                                    type: 'textbox',
                                    options: {
                                        required: true,
                                        width: 100
                                    }
                                },*/
                                formatter: function (val, rec) {
                                    let valTem = val ? val : '--'
                                    return "<a style=\" color: blue;text-decoration: none; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"getImprovelDetail('" + rec.impId
                                        + "')\">" + valTem + "</a>"
                                }
                            },
                            {
                                field: 'impDutyPersonCode',
                                title: '负责人code',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impDutyPersonName',
                                title: '负责人',
                                /*editor: {
                                    type: 'combobox',
                                    options: {
                                        required: true,
                                        width: 100
                                    }
                                },*/
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impApprovelCode',
                                title: '复核人code',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'impApprovelName',
                                title: '复核人',
                                /* editor: {
                                     type: 'textbox',
                                     options: {
                                         required: true,
                                         width: 100
                                     }
                                 },*/
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'status',
                                title: '状态',
                                formatter: function (val, rec) {
                                    return val ? formatStatus(val) : ''
                                }
                            }
                        ]
                    ],
                    onEndEdit: function (index, row) {
                        var ed = $(this).datagrid('getEditor', {
                            index: index,
                            field: 'impDutyDeptCode'
                        });
                        row.impDutyDeptName = $(ed.target).combobox('getText');
                    },

                    onClickCell: function (rowIndex, field, value) {
                        if (editIndex != rowIndex) {
                            if (endEditing()) {
                                $('#improes').datagrid('selectRow', rowIndex)
                                    .datagrid('beginEdit', rowIndex);
                                var ed = $('#improes').datagrid('getEditor', { index: rowIndex, field: field });
                                if (ed) {
                                    ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                                }
                                editIndex = rowIndex;
                            } else {
                                setTimeout(function () {
                                    $('#improes').datagrid('selectRow', editIndex);
                                }, 0);
                            }
                        }
                    }
                })
            }

            function setOosItemDataGrid(data) {
                $('#oosItems').datagrid({
                    data, data,
                    iconCls: 'icon-application',
                    clientPaging: true,
                    remoteFilter: false,
                    filterDelay: 0,
                    width: 850,
                    height: 300,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pagination: false,
                    columns: [
                        [
                            {
                                field: 'itemId',
                                title: '异常项id',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'osId',
                                title: 'oosID',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'itemName',
                                title: '分析项',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'itemExceptionDescr',
                                title: '异常情况',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            }
                        ]
                    ]
                })
            }

            function setOosTaskDataGrid(data) {
                $('#tasks').datagrid({
                    data, data,
                    iconCls: 'icon-application',
                    clientPaging: true,
                    remoteFilter: false,
                    filterDelay: 0,
                    width: 850,
                    height: 300,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pagination: false,
                    columns: [
                        [
                            {
                                field: 'taskId',
                                title: '任务id',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'osId',
                                title: 'oosID',
                                hidden: true,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'deptName',
                                title: '执行部门',
                                formatter: function (val, rec, index) {
                                    let valTem = val ? val : '--'
                                    return "<a style=\" color: blue;text-decoration: none; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"getTaskDetail('" + rec.taskId
                                        + "')\">" + valTem + "</a>"
                                }
                            },
                            {
                                field: 'executName',
                                title: '执行人',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },

                            {
                                field: 'taskContent',
                                title: '情况说明',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'planCompleteTime',
                                title: '计划完成时间',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'commitTime',
                                title: '提交时间',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'executor',
                                title: '执行人账号',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },

                            {
                                field: 'status',
                                title: '状态',
                                formatter: function (val, rec) {
                                    return val ? formatStatus(val) : ''
                                }
                            }
                        ]
                    ]
                })

            }

            function getTaskDetail(taskId) {
                if (!taskId || 'undefined' == taskId) {
                    return
                }
                $.ajax({
                    type: 'get',
                    url: 'qm/oos/task/selectInfor?taskId=' + taskId,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 60200) {
                            let oosTask = data.data
                            $('#taskId').val(taskId)
                            $('#executDeptName').textbox('setValue', oosTask.executDeptName)
                            $('#executName').textbox('setValue', oosTask.executName)
                            $('#planCompleteTime').textbox('setValue', oosTask.planCompleteTime)
                            $('#commitTime').textbox('setValue', oosTask.commitTime)
                            $('#taskContent').textbox('setValue', oosTask.taskContent)
                            getTaskFileList(oosTask.taskId)
                            $('#taskDetaillWindow').window('open')
                            $('#taskTabs').tabs('select', 0)
                        } else {
                            $.messager.alert('消息', data.msg);
                        }
                    }
                })
            }

            function getImprovelDetail(impId) {
                if (!impId || 'undefined' == impId) {
                    return
                }
                $.ajax({
                    type: 'get',
                    url: 'qm/oos/improves/selectInfor?impId=' + impId,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 60200) {
                            let oosImprove = data.data
                            $('#impId').val(impId)
                            $('#impExplain').textbox('setValue', oosImprove.impExplain)
                            $('#improveContent').textbox('setValue', oosImprove.improveContent)
                            $('#impPlanTime').textbox('setValue', oosImprove.impPlanTime)
                            $('#impRealTime').textbox('setValue', oosImprove.impRealTime)
                            $('#impDutyDeptName').textbox('setValue', oosImprove.impDutyDeptName)
                            $('#impDutyPersonName').textbox('setValue', oosImprove.impDutyPersonName)
                            $('#impApprovelName').textbox('setValue', oosImprove.impApprovelName)
                            $('#impCompleteDescr').textbox('setValue', oosImprove.impCompleteDescr)
                            getImproveFileList(oosImprove.impId)
                            $('#improvelDetaillWindow').window('open')
                            $('#impTabs').tabs('select', 0)
                        } else {
                            $.messager.alert('消息', data.msg);
                        }
                    }
                })
            }

            function setTabToolBar(row) {
                if ('0' == row.status) {
                    $('#tabs').tabs({
                        tools: [{
                            text: '保存',
                            iconCls: 'icon-save',
                            handler: function () {
                                save('save');
                            }
                        }, {
                            text: '完成',
                            iconCls: 'icon-ok',
                            handler: function () {
                                $.messager.confirm('提示', '点击完成后无法再次编辑，确定要提交吗?',
                                    function (r) {
                                        if (r) {
                                            save('submit')
                                        }
                                    });
                            }
                        }]
                    })
                    $('#tasks').datagrid({
                        toolbar: [{
                            text: '移除',
                            iconCls: 'icon-remove',
                            handler: function () {
                                let row = $('#tasks').datagrid('getSelected');
                                if (row) {
                                    $.messager.confirm('提示', '本条数据已输入的描述及附件会被删除，确定要删除吗?',
                                        function (r) {
                                            if (r) {
                                                // 获取索引
                                                let index = $('#tasks').datagrid('getRowIndex', row)
                                                // 删除前结束编辑
                                                $('#tasks').datagrid('endEdit', editIndex);
                                                editIndex = undefined;
                                                // 删除行
                                                $('#tasks').datagrid('deleteRow', index)
                                                // 删除数据库的该数据
                                                $.ajax({
                                                    type: "delete",
                                                    dataType: "json",
                                                    url: 'qm/oos/task/delete?taskId=' + row.taskId,
                                                    success: function (data) {
                                                        //  $.messager.alert('消息', data.msg);
                                                    },
                                                    error: function (XMLHttpRequest, textStatus,
                                                        errorThrown) {
                                                        //   $.messager.alert('消息', errorThrown);
                                                    }
                                                })

                                            }
                                        });
                                } else {
                                    $.messager.alert('消息', '请选中一条要删除的数据');
                                }
                            }
                        }, {
                            text: '退回',
                            iconCls: 'icon-back',
                            handler: function () {
                                let selectdTask = $('#tasks').datagrid('getSelected')
                                if (selectdTask) {
                                    // 如果状态为1，则将该行动项状态变为0
                                    if (selectdTask.status == '1') {
                                        $.messager.confirm('提示', '确定要退回吗?',
                                            function (r) {
                                                if (r) {
                                                    backUpTask(selectdTask)
                                                }
                                            });

                                    } else {
                                        $.messager.alert('提示', '该行动项为进行中，无需退回')
                                        return
                                    }
                                } else {
                                    $.messager.alert('提示', '请选择要退回的行动项')
                                    return
                                }
                            }
                        }]
                    });
                    $('#improes').datagrid({
                        toolbar: [
                            {
                                text: '新增',
                                iconCls: 'icon-add',
                                handler: function () {
                                    $('#improes').datagrid('appendRow', {});
                                }
                            }, '-',
                            {
                                text: '移除',
                                iconCls: 'icon-remove',
                                handler: function () {
                                    let row = $('#improes').datagrid('getSelected');
                                    if (row) {
                                        $.messager.confirm('提示', '本条数据已输入的整改描述及附件会被删除，确定要删除吗?',
                                            function (r) {
                                                if (r) {
                                                    // 获取索引
                                                    let index = $('#improes').datagrid('getRowIndex', row)
                                                    // 删除前结束编辑
                                                    $('#improes').datagrid('endEdit', editIndex);
                                                    editIndex = undefined;
                                                    // 删除行
                                                    $('#improes').datagrid('deleteRow', index)
                                                    // 删除数据库的该数据
                                                    $.ajax({
                                                        type: "delete",
                                                        dataType: "json",
                                                        url: 'qm/oos/improves/delete?impId=' + row.impId,
                                                        success: function (data) {
                                                            $.messager.alert('消息', data.msg);
                                                        },
                                                        error: function (XMLHttpRequest, textStatus,
                                                            errorThrown) {
                                                            $.messager.alert('消息', errorThrown);
                                                        }
                                                    })

                                                }
                                            });
                                    } else {
                                        $.messager.alert('消息', '请选中一条要删除的数据');
                                    }
                                }
                            }, {
                                text: '退回',
                                iconCls: 'icon-back',
                                handler: function () {
                                    let selectdImp = $('#improes').datagrid('getSelected')
                                    if (selectdImp) {
                                        // 如果状态为1，则将该行动项状态变为0
                                        if (selectdImp.status == '1') {
                                            $.messager.confirm('提示', '确定要退回吗?',
                                                function (r) {
                                                    if (r) {
                                                        backUpImp(selectdImp)
                                                    }
                                                });

                                        } else {
                                            $.messager.alert('提示', '该整改项进行中，无需退回')
                                            return
                                        }
                                    } else {
                                        $.messager.alert('提示', '请选择要退回的整改项')
                                        return
                                    }
                                }
                            }]
                    });
                } else {
                    $('#tabs').tabs({
                        tools: ''
                    })
                }
            }

            // 退回行动项
            function backUpTask(obj) {
                if (!obj) return
                $.ajax({
                    type: 'GET',
                    url: 'qm/oos/task/backUp?' + 'taskId=' + obj.taskId,
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', data.msg);
                            return
                        } else {
                            $('#detaillWindow').window('close');
                            oosDataDetailAjax(obj.osId)
                            $('#tabs').tabs('select', 2)
                            $.messager.alert('消息', data.msg);
                        }

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                })

            }

            // 退回整改项
            function backUpImp(obj) {
                if (!obj) return
                $.ajax({
                    type: 'GET',
                    url: 'qm/oos/improves/backUp?' + 'impId=' + obj.impId,
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', data.msg);
                            return
                        } else {
                            $('#detaillWindow').window('close');
                            oosDataDetailAjax(obj.osId)
                            $('#tabs').tabs('select', 3)
                            $.messager.alert('消息', data.msg);
                        }

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                })

            }

            function formatStatus(val) {
                let str = ''
                switch (val) {
                    case '0':
                        str = '进行中';
                        break;
                    case '1':
                        str = '已完成';
                        break;
                    /*case '2':
                        str = '延期';
                        break;*/
                    default:
                        str = ''
                }
                return str

            }

            function bindgrid() {
                var startTime = $('#startTime').datebox('getValue')
                var endTime = $('#endTime').datebox('getValue')
                var status = $('#select-status').combobox('getValue');
                $('#dg').datagrid(
                    {
                        title: '',
                        queryParams: {
                            startTime: startTime,
                            endTime: endTime,
                            status: status
                        },
                        url: "qm/oos/data/selectList",
                        iconCls: 'icon-application',
                        width: getWidth(0.98),
                        height: 400,
                        nowrap: true,
                        filterDelay: 0,
                        rownumbers: true,
                        animate: false,
                        collapsible: false,
                        clientPaging: false,
                        remoteFilter: true,
                        singleSelect: true,
                        pagination: true,
                        remoteSort: true,
                        frozenColumns: [[]],
                        columns: [[{
                            field: 'osId',
                            title: ' OOS主键',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osCode',
                            title: 'OOS编码',
                            sortable: true,
                            formatter: function (val, rec, index) {
                                return '<a style="text-decoration: none;" href="javascript:void(0)" onclick="detail(' + index +
                                    ')">' + (val ? val : '') + '</a>'
                            }
                        }, {
                            field: 'osSamplingTime',
                            title: '采样时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osSampleName',
                            title: '产品名称',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osSampleCode',
                            title: '样品编码',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osNoticeType',
                            title: '通知单类型',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osOsLevel',
                            title: '级别',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osMerchantName',
                            title: '客商名称',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osBatchCode',
                            title: '产品批号',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osPackageDescr',
                            title: '包装规格',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osCarNo',
                            title: '车牌号',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'osPackageQuantity',
                            title: '包装数量',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'status',
                            title: '状态',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? formatStatus(val) : '';
                            }
                        }, {
                            field: 'process',
                            title: '进度',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'createTime',
                            title: '创建时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }]],
                        /*  toolbar: [
                              {
                              text: '增加',
                              iconCls: 'icon-add',
                              handler: function () {
                                  $('#fm').form('clear');
                                  $('#add').window('open');
                              }
                          },
                              '-',
                              {
                                  text: '编辑',
                                  iconCls: 'icon-edit',
                                  handler: function () {
                                      editrow()
                                  }
                              },
                              '-',
                              {
                                  text: '删除',
                                  iconCls: 'icon-cancel',
                                  handler: function () {
                                      var row = $('#dg').datagrid(
                                          'getSelected');
                                      if (row) {
                                          $.messager.confirm('提示', '确定要删除这个吗?', function (r) {
                                              if (r) {
                                                  del(row);
                                              }
                                          });
                                      }
                                  }
                              }],*/
                        onLoadSuccess: function () {
                        },
                        onDblClickRow: function () {
                            editrow();
                        }
                    });
                $('#dg').datagrid('enableFilter');
            }

            /************文件处理部分*************/
            /**
             *文件框改变事件
             */
            function changeFile() {
                var files = $("#uploadpicker").prop("files");
                $.each(
                    files,
                    function (index, item) {
                        var choiseFile = $("#checkfileList>li");
                        if (choiseFile.length > 0) {//文件去重
                            var count = 0;
                            $.each(choiseFile, function (index1, item1) {
                                if (item.name == item1.innerText) {
                                    count++;
                                }
                            });
                            if (count == 0) {
                                if (checkFileLength(item.size)) {
                                    if (item.name.includes('&') || item.name.includes(' ')) {
                                        alert('文件名不能包含&、空格等特殊字符！');
                                        return;
                                    }
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + item.name
                                            + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                            + item.name
                                            + "')\">删除</a>"
                                            + "</li>");
                                    selectedFileList.push(item);
                                    AddMoushover();
                                }
                            }
                        } else {
                            if (checkFileLength(item.size)) {
                                if (item.name.includes('&') || item.name.includes(' ')) {
                                    alert('文件名不能包含&、空格等特殊字符！');
                                    return;
                                }
                                $("#checkfileList")
                                    .append(
                                        "<li class=\"fileinfo\">"
                                        + item.name
                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                        + item.name
                                        + "')\">删除</a>"
                                        + "</li>");
                                selectedFileList.push(item);
                                // 										sselectedFileNameList.push(item.name);
                                AddMoushover();
                            }
                        }
                    });
            }

            /**
             *    判断文件是否超过限制大小
             * @param fileLen
             * @returns {boolean}
             */
            function checkFileLength(fileLen) {
                if (fileLen > 102400000) {
                    $.messager.alert("提示", "上传文件大小不能超过100M", "error");
                    return false;
                }
                return true;
            }

            /**
             * //添加鼠标经过事件，鼠标划过时显示“删除”
             * @constructor
             */
            function AddMoushover() {
                $(".fileinfo").hover(function () {
                    $(this).find("a").last().css("display", "");
                }, function () {
                    $(this).find("a").last().css("display", "none");
                });
            }

            /**
             * //添加鼠标经过事件，鼠标划过时显示“删除”--task
             * @constructor
             */
            function AddTaskMoushover() {
                $(".taskFileinfo").hover(function () {
                    $(this).find("a").last().css("display", "");
                }, function () {
                    $(this).find("a").last().css("display", "none");
                });
            }

            /**
             * //添加鼠标经过事件，鼠标划过时显示“删除”--improve
             * @constructor
             */
            function AddImproveMoushover() {
                $(".impFileinfo").hover(function () {
                    $(this).find("a").last().css("display", "");
                }, function () {
                    $(this).find("a").last().css("display", "none");
                });
            }

            /**
             *  移除已选择的文件
             */

            function RemoveFile(obj, fileId) {

                $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                    if (e) {
                        let index = $("#checkfileList>li").index($(obj).parent());
                        selectedFileList.splice(index, 1);
                        $(obj).parent().remove();
                        // 					var index1 = $.inArray(filename, sselectedFileNameList);
                        // 					sselectedFileNameList.splice(index1, 1);
                        $.ajax({
                            type: "post",
                            url: 'file/deleteFile?fileId=' + fileId,
                            success: function (data) {
                                $.messager.alert('消息', data);
                            },
                            error: function (XMLHttpRequest, textStatus,
                                errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        });
                    }
                });
            }

            /**
             * 取得该条OOS数据所属的文件列表
             * @param row
             */
            function getFileList(row) {
                $.ajax({
                    type: "post",
                    url: "file/getFileList",
                    data: {
                        fileTable: "qm_oos_data",
                        fileRow: row
                    },
                    success: function (data) {
                        const dataArray = eval(data);
                        initFile(dataArray);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            /**
             * 取得该条OOS数据Task项所属的文件列表
             * @param row
             */
            function getTaskFileList(row) {
                $.ajax({
                    type: "post",
                    url: "file/getFileList",
                    data: {
                        fileTable: "qm_oos_task",
                        fileRow: row
                    },
                    success: function (data) {
                        const dataArray = eval(data);
                        initTaskFile(dataArray);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            /**
             * 取得该条OOS数据整改措施项所属的文件列表
             * @param row
             */
            function getImproveFileList(row) {
                $.ajax({
                    type: "post",
                    url: "file/getFileList",
                    data: {
                        fileTable: "qm_oos_improves",
                        fileRow: row
                    },
                    success: function (data) {
                        const dataArray = eval(data);
                        initImproveFile(dataArray);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            /**
             * 初始化该条数据的文件列表
             * @param dataArray
             */
            function initFile(dataArray) {
                $("#checkfileList").empty();
                // 			sselectedFileNameList = [];
                selectedFileList = [];

            }

            /**
             *初始化各行动项的附件列表
             */
            function initTaskFile(dataArray) {
                $("#taskFileList").empty();
                // 			sselectedFileNameList = [];
                selectedTaskFileList = [];
                dataArray
                    .forEach(function (e, i, a) {
                        $("#taskFileList")
                            .append(
                                "<li class=\"taskFileinfo\">"
                                + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                + e.FILE_ID
                                + "')\">"
                                + e.FILE_NAME
                                + "</a>"
                                + "</li>");
                        // 						sselectedFileNameList.push(e.FILE_NAME);
                        // AddTaskMoushover();
                    });
            }

            /**
             *初始化各措施项的附件列表
             */
            function initImproveFile(dataArray) {
                $("#impFileList").empty();
                // 			sselectedFileNameList = [];
                selectedImproveFileList = [];
                dataArray
                    .forEach(function (e, i, a) {
                        $("#impFileList")
                            .append(
                                "<li class=\"impFileinfo\">"
                                + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                + e.FILE_ID
                                + "')\">"
                                + e.FILE_NAME
                                + "</a>"
                                + "</li>");
                        // 						sselectedFileNameList.push(e.FILE_NAME);
                        // AddImproveMoushover();
                    });
            }

            function downloadFile(fileName, fileRow) {
                let url = 'api/file/download?id=' + fileRow
                let xhr = new XMLHttpRequest()
                xhr.open('GET', url, true)
                xhr.setRequestHeader('token', localStorage.getItem('token'));
                xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                xhr.responseType = 'blob'
                xhr.onload = function (data) {
                    if (this.status == 200) {
                        let blob = this.response
                        let reader = new FileReader()
                        reader.readAsDataURL(blob)
                        reader.onload = function (e) {
                            let a = document.createElement('a')
                            a.download = fileName
                            a.href = e.target.result
                            $('body').append(a)
                            a.click()
                            $(a).remove()
                        }
                    } else {

                    }
                }
                xhr.send()
            }

            /**
             * 保存附件
             */

            function saveAttch(row, obj, action) {
                obj.osId = row
                let saveNum = 0
                if (selectedFileList.length > 0) {
                    $.each(selectedFileList, function (index, item) {
                        load();
                        var dataform = new FormData();
                        dataform.append("file", item);
                        var xmlhttp = null;
                        if (window.XMLHttpRequest) {// code for all new browsers
                            xmlhttp = new XMLHttpRequest();
                        } else if (window.ActiveXObject) {// code for IE5 and IE6
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        if (xmlhttp != null) {
                            xmlhttp.open("POST", "api/file/springUpload?fileRow=" + row
                                + "&fileTable=qm_oos_data&fileName="
                                + item.name, true);
                            xmlhttp.setRequestHeader('token', localStorage.getItem('token'));
                            xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                            xmlhttp.send(dataform);
                            xmlhttp.onreadystatechange = callbackMethods;
                        } else {
                            alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                        }

                        function callbackMethods() {
                            if (xmlhttp.readyState == 4) {
                                if (xmlhttp.status == 200) {
                                    saveNum += 1
                                }
                                if (saveNum == selectedFileList.length) {
                                    disLoad();
                                    if ('submit' == action) {
                                        commit(obj)
                                    }
                                }
                            } else {
                                if (xmlhttp.status == 500) {
                                }
                            }
                        }
                    });
                } else {
                    if ('submit' == action) {
                        commit(obj)
                    }
                }
            }
        </script>

        </html>